﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Text;

namespace TruyenAudio
{
    class DBhelper
    {
        //Them Truyen Tinh Yeu
        public static void ADDLove(TINHYEU tinhyeu)
        {
            using (var context = new CSDLTruyenContext(CSDLTruyenContext.ConnectionString))
            {
                if (context.DatabaseExists())
                {
                    context.TINHYEU.InsertOnSubmit(tinhyeu);
                    context.SubmitChanges();
                }
            }
        }

        //lay ra cac the loai truyen
        public static List<TheLoai> GetTheLoai()
        {
            List<TheLoai> employees;
            using (var context = new CSDLTruyenContext(CSDLTruyenContext.ConnectionString))
            {
                employees = (from emp in context.TheLoai select emp).ToList();
            }

            return employees;
        }
        public static List<TRUYEN> GetDanhSachTruyen(string Tentl)
        {
            List<TRUYEN> truyen;
            using (var context = new CSDLTruyenContext(CSDLTruyenContext.ConnectionString))
            {
                truyen = (from emp in context.TRUYEN from tl in context.TheLoai where emp.MaTheLoai==tl.MaTheLoai && tl.TenTheLoai == Tentl select emp).ToList();
            }

            return truyen;
        }
        public static List<KIEMHIEP> gettaptruyen(string TenTruyen)
        {
            List<KIEMHIEP> truyen;
            using (var context = new CSDLTruyenContext(CSDLTruyenContext.ConnectionString))
            {
                truyen = (from tr in context.TRUYEN from kiemhiep in context.KIEMHIEP where kiemhiep.MaTryen == tr.MaTruyen && tr.TenTruyen == TenTruyen select kiemhiep).ToList();
            }

            return truyen;
        }
    }
}
